package com.yixing.tech.common.base;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.yixing.tech.common.enums.YesOrNo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.Date;
import java.util.List;

/**
 * @author yixing tech
 * at 2021/12/15
 * describe：
 */
@Data
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@Document
@JsonIgnoreProperties(allowGetters = true, value = {"createTime", "updateTime"})
public class BasePO {
    @Id
    @Indexed
    public String id;
    @Indexed
    public String tenantId;
    @Indexed
    public String createId;
    public String createName;
    @CreatedDate
    public Date createTime;
    @LastModifiedDate
    public Date updateTime;
    @Indexed
    public String updateId;
    public String updateName;
    public String departmentId;
    @Indexed
    public Integer isDelete = YesOrNo.NO.ordinal();

    public Sort sortCondition;

    public List<Sort> sortConditions;

    @Data
    @Accessors(chain = true)
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Sort {
        public String code;
        public String direction;

        public static Sort defaultSort(){
            return new Sort("_id", "desc");
        }
    }

    {
        sortCondition = Sort.defaultSort();
    }
}
